package cn.com.joycode.nimble.admin.security.authentication;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class NimbleAdminAuthenticationManager extends ProviderManager {

    public NimbleAdminAuthenticationManager(NimbleAdminAuthenticationProvider nimbleAdminAuthenticationProvider) {
        super(nimbleAdminAuthenticationProvider);
    }

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        log.info(this.getClass().getName());
        for (AuthenticationProvider authenticationProvider : getProviders()) {
            if (authenticationProvider.supports(authentication.getClass())) {
                return authenticationProvider.authenticate(authentication);
            }
        }
        return null;
    }
}
